# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/265858

import string
import win32api
import win32con
import win32file
import traceback
from StringIO import StringIO

class GetSysInformation:
    def __init__(self):
        # variable to write a flat file
        self.HKEY_LOCAL_MACHINE = win32con.HKEY_LOCAL_MACHINE
        self.CONST_OS_SUBKEY = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"

    def getSysInfo(self):
        res = []
        try:

            # getting OS Details
            hCounter=0
            # opening the sub key to get the processor name
            hHandle = win32api.RegOpenKeyEx(self.HKEY_LOCAL_MACHINE,self.CONST_OS_SUBKEY,0,win32con.KEY_ALL_ACCESS)
            hNoOfKeys = win32api.RegQueryInfoKey(hHandle)[1]
            while hCounter < hNoOfKeys:           
                hData = win32api.RegEnumValue(hHandle,hCounter)
                #if hData[0] not in ['DigitalProductId', 'LicenseInfo']: print hData[0], hData[1]
                if hData[0] in  ['ProductName', 'CSDVersion', 'CurrentVersion']:
                    res.append(hData[1])
                hCounter = hCounter + 1

        except:
            res = "EXCEPTION",""
            #print pwintypes.error
            print '\n',traceback.print_exc(),'\n'
            #print error

        return string.join(res, ', ')

def main():
    versions = {  'Microsoft Windows XP, 5.1, Service Pack 2': 'MS Windows XP, SP2, v5.1, 32bit'
		, 'Microsoft Windows XP, 5.2, Service Pack 2': 'MS Windows XP, SP2, v5.2, 64bit'
		, '6.0, Windows Vista (TM) Enterprise, Service Pack 1': 'MS Windows Vista Enterprise, SP1'
        , 'EXCEPTION': 'Error occured.'        }
    return versions[GetSysInformation().getSysInfo()]

if __name__ == "__main__":
    """ """
    """
    if main() == 'MS Windows XP, SP2, v5.1, 32bit':
        print 'Win XP SP2'
    else:
        print 'it is non Win XP SP2, 32bit'
    """
    #print 'PRETTY PRINT :: ', main()
    #print 'RAW PRINT :: ', GetSysInformation().getSysInfo()
    print main()









    '''
    windows xp, sp2, 32bit
    
    CurrentBuild 1.511.1 () (Obsolete data - do not use)
    InstallDate 1162315991
    ProductName Microsoft Windows XP
    SoftwareType SYSTEM
    CurrentVersion 5.1
    CurrentBuildNumber 2600
    BuildLab 2600.xpsp_sp2_gdr.070227-2254
    CurrentType Uniprocessor Free
    CSDVersion Service Pack 2
    SystemRoot C:\WINDOWS
    SourcePath C:\I386
    PathName C:\WINDOWS
    '''

    '''
    windows xp, sp2, 64 bit
    
    CurrentBuild 1.511.1 () (Obsolete data - do not use)
    InstallDate 1132516918
    ProductName Microsoft Windows XP
    RegisteredOwner Mpc915
    SoftwareType SYSTEM
    CurrentVersion 5.2
    CurrentBuildNumber 3790
    BuildLab 3790.srv03_sp2_gdr.070321-2337
    CurrentType Multiprocessor Free
    CSDVersion Service Pack 2
    CSDBuildNumber 4045
    SystemRoot C:\WINDOWS
    SourcePath D:\AMD64
    PathName C:\WINDOWS
    '''
